<?php 
/*
Template Name: Product
*/

get_header(); 

$child_category = get_the_category();
$child_category = $child_category[0];
$parent_category = get_category_parents($child_category->cat_ID);
$subcategories = get_categories(array('parent' =>  $child_category->category_parent, 'hide_empty' => 0, 'orderby' => 'id'));
?>
<ul class="f-product-menu row-fluid f-showPhone nav nav-tabs">
		<?php
		$counterMenu = 0; 
		foreach($subcategories as $subcategory) 
		{ 
		$counterMenu++;
		?>
			<li class="<?php if($counterMenu==1){echo 'active';}?>"><a href="#<?php echo $subcategory->name;?>" data-toggle="tab"><?php echo $subcategory->name;?></a></li>
		<?php } ?>
	</ul><!-- cat navbar -->
<div style="display:none;"><!-- Preload images -->
   <img src="/wp-content/themes/fructa/images/product-block-bg-hover-last.png" />
   <img src="/wp-content/themes/fructa/images/product-block-bg-hover-first.png" />
   <img src="/wp-content/themes/fructa/images/product-block-bg-hover.png" />
</div>
<div class="f-product-cat row-fluid tab-content">
	<?php 
	$counter = 0;
	foreach($subcategories as $subcategory) {
		$counter++;
		?>
		<div id="<?php echo $subcategory->name;?>" class="span4 f-product-block tab-pane <?php if($counter==1){echo 'first active';}else if($counter==count($subcategories)){echo 'last';}?>">
			<?php
			$the_query = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'inherit', 'category_name' =>  $subcategory->slug));
			if ($the_query->have_posts()) {
				while ($the_query->have_posts()) {
					$the_query->the_post();					
					echo wp_get_attachment_image($attachment->ID, 'full');					
				}
			}
			wp_reset_postdata();
			?>
			<ul>
				<h2><?php echo $subcategory->name;?></h2>
				<?php 
				$the_query = new WP_Query(array('post_type' => 'pages', 'post_status' => 'publish', 'category_name' =>  $subcategory->slug, 'orderby'=>'menu_order', 'order' => 'ASC'));
				if ($the_query->have_posts()) {
					while ($the_query->have_posts()) {
						$the_query->the_post();					
						?>
						<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
						<?php				
					}
				}				
				?>
				<br>
				<i>
				<?php 
				echo category_description($subcategory->cat_ID);
				wp_reset_postdata();
				?>	
				</i>
			</ul>
		</div>
		<?php
	} 
	?>
</div><!-- f-product-cat row-fluid -->
</div><!-- f-logo-menu -->
</div><!-- f-header -->
<div class="f-product-page container">
	<!-- <h2><?php //the_title(); ?></h2> -->
	<?php the_content(); ?>
</div>
<?php get_footer(); ?>
<script>
$(document).ready(function(){
	scrollToProduct();
})
</script>